package com.yanqu.road.server.manger;

import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.entity.monopolymarket.MonopolyMarket;
import com.yanqu.road.entity.monopolymarket.config.*;
import com.yanqu.road.entity.monopolymarket.group.IMonopolyMarketGroup;
import com.yanqu.road.entity.monopolymarket.office.MonopolyMarketOfficeSeatConfig;
import com.yanqu.road.entity.monopolymarket.resgrab.MonopolyMarketResGrabMap;
import com.yanqu.road.entity.monopolymarket.resgrab.MonopolyMarketResGrabPointValue;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.utils.date.DateHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.*;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/20 10:33
 */
public class MonopolyMarketCommonMgr {

    private static final Logger logger = LogManager.getLogger(MonopolyMarketCommonMgr.class.getName());

    /**
     * 榷场系统位
     */
    public static final int SYSTEM_BIT = 0b1111;

    /**
     *
     */
    public static final String MONOPOLYMARKET_LEVEL_NUM = "1;1|2;2|3;2|4;3|5;3|6;3|7;3|8;3|9;3";

    /**
     * 榷署每个等级官员 每行数量
     */
    public static Map<Integer,Integer> perLineNumMap = new HashMap<>();

    static {
        String[] levelNumStr = MONOPOLYMARKET_LEVEL_NUM.split("\\|");
        for (String item : levelNumStr){
            if(item.contains(";")){
                String[] levelNum = item.split(";");
                int level = Integer.valueOf(levelNum[0]);
                int num = Integer.valueOf(levelNum[1]);
                perLineNumMap.put(level, num);
            }
        }
    }

    /**
     * 计算榷署位置的类型
     */
    public static int calOfficePosLevel(List<MonopolyMarketOfficeSeatConfig> seatConfigList, int posIndex){
        int level = 0;
        for(MonopolyMarketOfficeSeatConfig item : seatConfigList){
            if(posIndex >= item.startIndex && posIndex <= item.endIndex){
                return item.getLevel();
            }
        }
        return level;
    }

    /**
     * 计算榷署每隔等级 起 始位置
     * @param serverNum
     * @param resConfigList
     * @param resExtendParamConfigMap
     * @return
     */
    public static List<MonopolyMarketOfficeSeatConfig> calMonopolyMarketOfficeSeatConfigList(int serverNum,List<MonopolyMarketResConfigData> resConfigList, Map<Integer, List<MonopolyMarketResExtendParam>> resExtendParamConfigMap){
        List<MonopolyMarketOfficeSeatConfig> list = new ArrayList<>();
        int startIndex = 0;
        for (MonopolyMarketResConfigData item : resConfigList){
            int endIndex = startIndex;
            List<MonopolyMarketResExtendParam> extendParamList = resExtendParamConfigMap.get(item.getId());
            for (int i = 0; i < extendParamList.size(); i++) {
                MonopolyMarketResExtendParam extendParam = extendParamList.get(i);
                if(serverNum <= extendParam.getServerNum() || (extendParamList.size()-1) == i){
                    int lineNum = perLineNumMap.getOrDefault(item.getLevel(),0);
                    endIndex += extendParam.getNum() * lineNum;
                    break;
                }
            }
            int tempEndIndex = endIndex - 1;
            if(startIndex > tempEndIndex){
                logger.error("榷署配置异常 资源点 结束位置大于开始位置，level:{},startIndex:{},endIndex:{}",item.getLevel(),startIndex,tempEndIndex);
                continue;
            }
            list.add(new MonopolyMarketOfficeSeatConfig(item.getLevel(),startIndex,tempEndIndex));
            startIndex = endIndex;
        }
        return list;
    }


    public static MonopolyMarketResExtendParam getMonopolyMarketResConfigData(int serverNum,List<MonopolyMarketResExtendParam> extendParamList) {
        MonopolyMarketResExtendParam tempParam = null;
        for (int i = 0; i < extendParamList.size(); i++) {
            tempParam = extendParamList.get(i);
            if(serverNum <= tempParam.getServerNum()){
                break;
            }
        }
        return tempParam;
    }


    /**
     * 计算产出速度
     *
     * @param serverNum
     * @param reward
     * @param rewardAdd
     * @param id
     * @param resConfig
     * @param no
     * @return
     */
    public static int calResRate(int serverNum, int reward, int rewardAdd, int id, MonopolyMarketResConfig resConfig, int no) {
        MonopolyMarketResExtendParam param = MonopolyMarketCommonMgr.getMonopolyMarketResConfigData(serverNum, resConfig.resExtendParamMap.get(id));
        long coefficient = param.getCoefficient();
        no = Math.max(no, 1);
        int rate = (int) ((reward * coefficient - (no - 1) * rewardAdd + 1000 - 1) / 1000);
        return rate;
    }

    /**
     * 初始化地图  左上角为（0,0） index = 0     01234----->
     *                                         1
     *                                         2
     *                                         3
     * @param type
     * @param group
     * @param configList 配置
     */
    public static MonopolyMarketResGrabMap initResGrabMap(int type , IMonopolyMarketGroup group, List<MonopolyMarketResConfigData> configList, MonopolyMarketResConfig monopolyMarketResConfig,boolean isShowLog){
        logger.info("开始初始化榷场地图。groupId :{},type:{},changTime:{}",group.getMonopolyMarketGroupId(),type,group.getMonopolyMarketChangeTime());
        Random random = new Random(group.getMonopolyMarketChangeTime() + group.getMonopolyMarketGroupId() + type);
        // 实际据点数量
        int pointNum = calSeatNum(group,configList,monopolyMarketResConfig.resExtendParamMap);
        // 地图边长
        int side = (int)Math.ceil(Math.pow(pointNum * monopolyMarketResConfig.getMapSize() / 1000, 0.5));
        // 最大长度
        double maxLength = Math.pow(0.5, 0.5) * side;
        // 格子总数
        int totalNum = side * side;
        List<MonopolyMarketResGrabPointValue> pointList = new ArrayList<>(totalNum);
        // 循环次数
        for (int j = 0; j < totalNum; j++) {
            // 据点到中心点的长度
            int x = j % side;
            int y = j / side;
            double xy = Math.sqrt(Math.pow(x - side/2,2) + Math.pow(y - side/2,2));
            double value = (1 - xy / maxLength) * monopolyMarketResConfig.getMapMidValue();
            MonopolyMarketResGrabPointValue pointValue = new MonopolyMarketResGrabPointValue();
            pointValue.value = value;
            pointValue.index = j;
            pointList.add(pointValue);
        }
        for (int i = 1; i <= monopolyMarketResConfig.getMapRound(); i++) {
            int m = monopolyMarketResConfig.getMapBase() + (i - 1) * monopolyMarketResConfig.getMapAdd();
            int turns = (int)Math.ceil(side / 2);
            for (int j = 0; j < turns; j++) {
                int length = side - j * 2 -1;
                // 起点
                // 左到右
                for (int k = 0; k < length; k++) {
                    int x = j + k;
                    int y = j;
                    checkPoint(random,x,y,side,m,pointList);
                }
                // 右上到右下
                for (int k = 0; k < length; k++) {
                    int x = side - 1 - j;
                    int y = k + j;
                    checkPoint(random,x,y,side,m,pointList);
                }
                // 右下到左下
                for (int k = 0; k < length; k++) {
                    int x = side - 1 - j - k;
                    int y = side - 1 - j;
                    checkPoint(random,x,y,side,m,pointList);
                }
                // 左下到上
                for (int k = 0; k < length; k++) {
                    int x = j;
                    int y = side - 1 - j - k;
                    checkPoint(random,x,y,side,m,pointList);
                }
            }
        }
        pointList.sort((t1,t2)->{
            return Double.compare(t2.value,t1.value);
        });
        MonopolyMarketResGrabMap map = new MonopolyMarketResGrabMap();
        map.type = type;
        map.side = side;
        map.pointNum = totalNum;
        // 所有的据点index
        List<Integer> allIndexList = new ArrayList<>();
        for (int i = configList.size() - 1; i >= 0; i--) {
            MonopolyMarketResConfigData item = configList.get(i);

            MonopolyMarketResExtendParam extendParam = MonopolyMarketCommonMgr.getMonopolyMarketResConfigData(group.getMonopolyMarketServerList().size(),monopolyMarketResConfig.resExtendParamMap.get(item.getId()));
            List<Integer> list = map.levelIndexListMap.get(item.getLevel());
            if(list == null){
                list = new ArrayList<>();
                map.levelIndexListMap.put(item.getLevel(),list);
            }
            for (int j = 0; j < extendParam.getNum(); j++) {
                MonopolyMarketResGrabPointValue pointValue = pointList.remove(0);
                map.indexLevelMap.put(pointValue.index, item.getLevel());
                list.add(pointValue.index);
            }
            list.sort((t1,t2)->{ return Integer.compare(t1,t2); });
            allIndexList.addAll(list);
        }
        map.levelIndexListMap.put(0,allIndexList);

        map.indexLevelList = new ArrayList<>(totalNum);
        int index = 0;
        for (int i = 0; i < side; i++) {
            for (int j = 0; j < side; j++) {
                Integer level = map.indexLevelMap.getOrDefault(index++, 0);
                map.indexLevelList.add(level);
            }
        }
        if(isShowLog){
            // 打印地图
            int tempSide = side;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < map.indexLevelList.size(); i++) {
                int level = map.indexLevelList.get(i);
                if(level == 0){
                    sb.append("* ");
                }else {
                    sb.append(level+" ");
                }
                if(--tempSide == 0){
                    logger.info(sb);
                    tempSide = side;
                    sb.setLength(0);
                }
            }
        }
        logger.info("初始化榷场地图结束。groupId:{}, 地图边长：{},最大长度：{},实际可开采格子：{}",group.getMonopolyMarketGroupId(),side,maxLength,pointNum);
        return map;
    }

    /**
     * 检查格子
     * 格子判断如下：
     * 	计算格子周围九宫格包括自己的总数值为n
     * 	随机一个数r=random(0,1)
     * 	若r<n/m 则该格子数值+1，否则数值不变
     * @param random
     * @param x
     * @param y
     * @param side
     * @param m
     * @param pointList
     */
    private static void checkPoint(Random random ,int x, int y, int side,int m, List<MonopolyMarketResGrabPointValue> pointList){
//        logger.info("x:{}，y:{}",x, y );
        double n = calJiuGongGeValue(x, y ,side,pointList);
        double r = random.nextDouble();
        if(r < n / m){
            int index = calIndex(x,y,side);
            MonopolyMarketResGrabPointValue item = pointList.get(index);
            item.value = item.value + 1;
        }
    }

    /**
     * 计算周围九宫格的值
     * @return
     */
    private static double calJiuGongGeValue(int x,int y ,int side, List<MonopolyMarketResGrabPointValue> pointValueList){
        // 寻找九宫格的中心点
        int centerX = x;
        int centerY = y;
        if(centerX == 0 ){
            // 右移
            centerX += 1;
        }else if (centerX == side - 1){
            centerX -= 1;
        }
        if(centerY == 0 ){
            // 右移
            centerY += 1;
        }else if(centerY == side - 1){
            centerY -= 1;
        }
        Set<Integer> set = getAroundPoints(centerX, centerY,side,1);
        int index = calIndex(centerX, centerY,side);
        set.add(index);
        double totalValues = 0;
        for (Integer i : set){
            totalValues += pointValueList.get(i).value;
        }
//        logger.info("index : {},的九宫格为:{}",calIndex(x,y,side), set);
        return totalValues;
    }

    /**
     * 获得 中心点 周围 据点集合
     * @param x
     * @param y
     * @param side 地图边长
     * @param r 第几圈
     * @return
     */
    private static Set<Integer> getAroundPoints(int x,int y,int side,int r){
        Set<Integer> set = new HashSet<>();
        // 上
        int upX = x;
        int upY = y - r;
        set.addAll(getXPoints(upX,upY,side,r));
        // 下
        int downX = x;
        int downY = y + r;
        set.addAll(getXPoints(downX,downY,side,r));
        // 左
        int leftX = x - r;
        int leftY = y;
        set.addAll(getYPonits(leftX,leftY,side,r));
        // 右
        int rightX = x + r;
        int rightY = y;
        set.addAll(getYPonits(rightX,rightY,side,r));
        return set;
    }

    /**
     * 获得 在x轴上距离该点 小于等于r 的集合
     * @param x
     * @param y
     * @param side
     * @param r
     * @return
     */
    private static Set<Integer> getXPoints(int x,int y,int side,int r){
        Set<Integer> set = new HashSet<>();
        getValue(x, y,side,set);
        for (int i = 1; i <= r; i++) {
            getValue(x - i,y,side,set);
            getValue(x + i,y,side,set);
        }
        return set;
    }

    /**
     * 获得 在y轴上距离该点 小于等于r 的集合
     * @param x
     * @param y
     * @param side
     * @param r
     * @return
     */
    private static Set<Integer> getYPonits(int x, int y, int side, int r){
        Set<Integer> set = new HashSet<>();
        getValue(x, y,side,set);
        for (int i = 1; i <= r; i++) {
            getValue(x,y - i,side,set);
            getValue(x,y + i,side,set);
        }
        return set;
    }

    private static Integer getValue(int x,int y,int side,Set<Integer> set){
        if(x < 0 || x > side -1){
            return null;
        }
        if(y < 0 || y > side -1){
            return null;
        }
        int index = calIndex(x,y,side);
        set.add(index);
        return index;
    }

    /**
     * 计算点对应的 索引位置
     * @param x
     * @param y
     * @param side
     * @return
     */
    public static int calIndex(int x, int y ,int side){
        return x + y * side;
    }

    /**
     * 计算该分组位置总数量
     * @return
     */
    private static int calSeatNum(IMonopolyMarketGroup group, List<MonopolyMarketResConfigData> resConfigList,Map<Integer, List<MonopolyMarketResExtendParam>> resExtendParamMap){
        int totalSeatNum = 0;
        for (MonopolyMarketResConfigData item : resConfigList){
            MonopolyMarketResExtendParam extendParam = MonopolyMarketCommonMgr.getMonopolyMarketResConfigData(group.getMonopolyMarketServerList().size(),resExtendParamMap.get(item.getId()));
            totalSeatNum += extendParam.getNum();
        }
        return totalSeatNum;
    }


    /**
     * 获取 该时间 的榷署结束时间
     * @param time 要计算的时间
     * @param weekEndTime  周结束的时间
     * @return
     */
    public static int getResetOfficeTime(int time, int weekEndTime){
        return DateHelper.getWeekBeginTimestamp(time) + weekEndTime;
    }

    /**
     * 获取榷场 资源站产出道具id
     * @param type
     * @return
     */
    public static int getGoodsId(int type){
        int goodsId = 0;
        if(type == eMonopolyMarketResType.RES_KING.getValue()){
            goodsId = GameConfig.MONOPOLYMARKET_BAIYE_ID;
        }else if(type == eMonopolyMarketResType.RES_QUEEN.getValue()){
            goodsId = GameConfig.MONOPOLYMARKET_CAIYI_ID;
        }
        return goodsId;
    }

    /**
     * 检查后台榷场配的扩展参数是否正确
     * @return
     */
    public static boolean checkBackEndResConfig(MonopolyMarketBackEndConfig config,List<MonopolyMarketResConfigData> resConfigList) {
        // 后台的校验 配置是否都有配置各个据点拓展参数
        if(config == null){
            logger.error("后台没有榷场资源配置。");
            return false;
        }
        if(resConfigList == null || resConfigList.size() == 0){
            logger.error("榷场没有资源点配置t_p_monopoly_market_res。");
            return false;
        }
        for (MonopolyMarketResConfigData item : resConfigList) {
            if (item.getType() != eMonopolyMarketResType.FORTRESS.getValue() && !config.resExtendParamMap.containsKey(item.getId())) {
                logger.error("后台的榷场资源配置，没有配置t_p_monopoly_market_res 资源点的扩展参数。id:{}", item.getId());
                return false;
            }
        }
        return true;
    }


    /**
     * 边关要塞是否是休息期
     */
    public static boolean isRestFortress(){
        int now = DateHelper.getCurrentSecond();
        int weekBeginTime = DateHelper.getWeekBeginTimestamp(now);
        int restPeriodOpenSecond = weekBeginTime + ConfigMgr.getFortressRestPeriodEndSecond();
        int restPeriodEndSecond = weekBeginTime + ConfigMgr.getFortressRestPeriodEndSecond();
        if(restPeriodOpenSecond <= now && now < restPeriodEndSecond){
            return true;
        }
        return false;
    }

    /**
     * 边关要塞是否是派遣期
     */
    public static boolean isDispatchFortress(){
        int now = DateHelper.getCurrentSecond();
        int weekBeginTime = DateHelper.getWeekBeginTimestamp(now);
        int openSecond = weekBeginTime + ConfigMgr.getFortressDispatchPeriodOpenSecond();
        int endSecond = weekBeginTime + ConfigMgr.getFortressDispatchPeriodEndSecond();
        if(openSecond <= now && now < endSecond){
            return true;
        }
        return false;
    }

    /**
     * 边关要塞是否是采集期
     */
    public static boolean isCollectingFortress(){
        int now = DateHelper.getCurrentSecond();
        int weekBeginTime = DateHelper.getWeekBeginTimestamp(now);
        int openSecond = weekBeginTime + ConfigMgr.getFortressCollectingPeriodOpenSecond();
        int endSecond = weekBeginTime + ConfigMgr.getFortressCollectingPeriodEndSecond();
        if(openSecond <= now && now < endSecond){
            return true;
        }
        return false;
    }

    /**
     * 边关要塞是否是结算期
     */
    public static boolean isSettlementFortress(){
        int now = DateHelper.getCurrentSecond();
        int weekBeginTime = DateHelper.getWeekBeginTimestamp(now);
        int openSecond = weekBeginTime + ConfigMgr.getFortressSettlementPeriodOpenSecond();
        int endSecond = weekBeginTime + ConfigMgr.getFortressSettlementPeriodEndSecond();
        if(openSecond <= now && now < endSecond){
            return true;
        }
        return false;
    }


    /**
     * 本周的边关要塞是否结束
     */
    public static boolean isFortressEnd(MonopolyMarket monopolyMarket){
        int now = DateHelper.getCurrentSecond();
        if(monopolyMarket.group.getChangTime() > MonopolyMarketCommonMgr.getFortressDispatchOpenTime(now)){
            // 分组变更的时间 大于 本周派遣的开始时间 算结算了
            return true;
        }
        int endTime = DateHelper.getWeekBeginTimestamp(now) + ConfigMgr.getFortressCollectingPeriodEndSecond();
        if(now >= endTime){
            return true;
        }
        return false;
    }

    /**
     * 获取要塞上一周 采集期结束时间
     * @return
     */
    public static int getLastRoundFortressCollectEndTime(int now){
        // 本周结束的时间
        int thisWeekEndTime = DateHelper.getWeekBeginTimestamp(now) + ConfigMgr.getFortressCollectingPeriodEndSecond();
        // 上一周 集期结束时间
        return (int)(thisWeekEndTime - DateHelper.WEEK_SECONDS);
    }

    /**
     * 榷场 系统 是否开启
     * @param type
     * @return
     */
    public static boolean isSystemOpen(IMonopolyMarketGroup iMonopolyMarketGroup,int type){
        int now = DateHelper.getCurrentSecond();
        // 本周走的秒数
        int weekDiffTime = now - DateHelper.getWeekBeginTimestamp(now);
        // 今天走的秒数
        int todayDiffTime = now - DateHelper.getZeroTime(now);
        if(type == eMonopolyMarketResType.OFFICE.getValue()){
            if(ConfigMgr.getOfficeOpenSecond() <= weekDiffTime && weekDiffTime < ConfigMgr.getOfficeEndSecond()){
                return true;
            }
        }else if(type == eMonopolyMarketResType.RES_KING.getValue()){
            if(ConfigMgr.getResGrabKingOpenSecond() <= weekDiffTime && weekDiffTime < ConfigMgr.getResGrabKingEndSecond()){
                // 判断每天是否开启
                if(ConfigMgr.getKingDailyOpenTime() <= todayDiffTime && todayDiffTime < ConfigMgr.getKingDailyEndTime()){
                    return true;
                }
            }
        }else if(type == eMonopolyMarketResType.RES_QUEEN.getValue()){
            if(ConfigMgr.getResGrabQueenOpenSecond() <= weekDiffTime && weekDiffTime < ConfigMgr.getResGrabQueenEndSecond()){
                // 判断每天是否开启
                if(ConfigMgr.getQueenDailyOpenTime() <= todayDiffTime && todayDiffTime < ConfigMgr.getQueenDailyEndTime()){
                    return true;
                }
            }
        } else if(type == eMonopolyMarketResType.FORTRESS.getValue()){
            // 系统开关
            if(iMonopolyMarketGroup == null || iMonopolyMarketGroup.getMonopolyMarketFortressState() != 1){
                return false;
            }
            // 如果分组时间是大于本周派遣期的开始时间不让他进
            int openSecond = getFortressDispatchOpenTime(now);
            if( iMonopolyMarketGroup.getMonopolyMarketChangeTime() > openSecond){
                return false;
            }
            if(MonopolyMarketCommonMgr.isDispatchFortress() || MonopolyMarketCommonMgr.isSettlementFortress() || MonopolyMarketCommonMgr.isCollectingFortress()){
                return true;
            }
        }
        return false;
    }

    /**
     * 获取该时间 本周的要塞派遣开始时间
     * @param time
     * @return
     */
    public static int getFortressDispatchOpenTime(int time){
        int weekBeginTime = DateHelper.getWeekBeginTimestamp(time);
        int openSecond = weekBeginTime + ConfigMgr.getFortressDispatchPeriodOpenSecond();
        return openSecond;
    }

    /**
     * 获取要塞上一周结算期时间
     * @return
     */
    public static int getLastRoundFortressSettlementStartTime(int now){
        // 本周结束的时间
        int thisWeekSettlementEndTime = DateHelper.getWeekBeginTimestamp(now) + ConfigMgr.getFortressSettlementPeriodOpenSecond();
        // 上一周 集期结束时间
        return (int)(thisWeekSettlementEndTime - DateHelper.WEEK_SECONDS);
    }

    /**
     * 获取要塞上一周 采集期开始时间
     * @return
     */
    public static int getLastRoundFortressDispatchStartTime(int now){
        // 本周结束的时间
        int thisWeekSettlementEndTime = MonopolyMarketCommonMgr.getFortressDispatchOpenTime(now);

        return (int)(thisWeekSettlementEndTime - DateHelper.WEEK_SECONDS);
    }

    /**
     * 获取每周id
     * @param now s
     * @return
     */
    public static int getMonopolyMarketWeekId(int now){
        return Integer.valueOf(DateHelper.getPyyyyMMddDateString(now));
    }

    /**
     * 获取每周id
     * @return
     */
    public static int getMonopolyMarketWeekId(){
        return getMonopolyMarketWeekId(DateHelper.getWeekBeginTimestamp());
    }


    public static int getResGrabPointCD(int type){
        int cd = 0;
        if(type == eMonopolyMarketResType.RES_KING.getValue()){
            cd = GameConfig.MONOPOLYMARKET_REWARD_CD_2;
        }else if(type == eMonopolyMarketResType.RES_QUEEN.getValue()){
            cd = GameConfig.MONOPOLYMARKET_REWARD_CD_3;
        }
        return cd;
    }

    /**
     * 获取对应资源npc的血量
     * @param serverList
     * @param resConfig
     * @param configData
     * @return
     */
    public static String getNpcStr(List<Long> serverList,MonopolyMarketResConfig resConfig, MonopolyMarketResConfigData configData) {
        if (configData.getType() != eMonopolyMarketResType.RES_KING.getValue() && configData.getType() != eMonopolyMarketResType.RES_QUEEN.getValue()) {
            return "";
        }
        int averageOpenDayNum = MonopolyMarketCommonMgr.getAverageOpenDayNum(serverList, configData.getType());
        MonopolyMarketNpcBloodConfig tempMonopolyMarketNpcBloodConfig = null;
        String npcList = configData.getNpcList();
        for (MonopolyMarketNpcBloodConfig item : resConfig.getNpcBloodConfigList()) {
            if (tempMonopolyMarketNpcBloodConfig == null || item.getDay() <= averageOpenDayNum) {
                tempMonopolyMarketNpcBloodConfig = item;
            } else {
                break;
            }
        }
        if (tempMonopolyMarketNpcBloodConfig != null) {
            String npcBloodConfigStr = tempMonopolyMarketNpcBloodConfig.getNpcObjectStrMap().get(configData.getId());
            if (npcBloodConfigStr != null) {
                npcList = npcBloodConfigStr;
            }
        }
        return npcList;
    }


    /**
     * 获取该时间 本周的资源点派遣开始时间 s
     * @param time s
     * @return
     */
    public static int getResGrabDispatchOpenTime(int time, int type){
        int weekBeginTime = DateHelper.getWeekBeginTimestamp(time);
        int openSecond = 0;
        if(type == eMonopolyMarketResType.RES_KING.getValue()){
            openSecond = weekBeginTime + ConfigMgr.getResGrabKingOpenSecond();
        }else if(type == eMonopolyMarketResType.RES_QUEEN.getValue()){
            openSecond = weekBeginTime + ConfigMgr.getResGrabQueenOpenSecond();
        }
        return DateHelper.getZeroTime(openSecond);
    }

    /**
     * 当前榷场分组 平均开服天数
     * @param serverList
     * @param type
     * @return
     */
    public static int getAverageOpenDayNum(List<Long> serverList, int type) {
        // 本周榷场的开始时间
        int monopolyMarketOpenTime = MonopolyMarketCommonMgr.getResGrabDispatchOpenTime(DateHelper.getCurrentSecond(), type);
        // 取平均开服天数
        return ServerListMgr.getAverageOpenDayNum(serverList, monopolyMarketOpenTime);
    }

}
